// 蜂窝蜜造平台生成代码，如手工更改，请添加到 .beeignore 忽略生成
package com.fowo.api.controller;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fowo.api.common.model.IdListPo;
import com.fowo.api.common.model.IdPo;
import com.fowo.api.common.model.ImportRow;
import com.fowo.api.common.model.OptionItem;
import com.fowo.api.common.model.R;
import com.fowo.api.common.util.ResponseUtils;
import com.fowo.api.entity.PurchaseOrder;
import com.fowo.api.model.purchase.order.PurchaseOrderImportPo;
import com.fowo.api.model.purchase.order.PurchaseOrderItemVo;
import com.fowo.api.model.purchase.order.PurchaseOrderSearchParamPo;
import com.fowo.api.model.purchase.order.PurchaseOrderVo;
import com.fowo.api.service.PurchaseOrderService;
import com.fowo.api.sys.entity.SysFile;
import com.fowo.api.user.model.JwtUserInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import org.springframework.core.io.ClassPathResource;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.util.StreamUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@Tag(name = "采购订单")
@RequestMapping("/api/purchase-order")
@RestController
public class PurchaseOrderController {

  @Resource
  private PurchaseOrderService service;

  @Operation(summary = "查询结果")
  @GetMapping
  public R<List<PurchaseOrderItemVo>> search(
    PurchaseOrderSearchParamPo search
  ) {
    JwtUserInfo jwtUserInfo = JwtUserInfo.fromHeader();
    if (jwtUserInfo != null) {
      search.setCurrentUserId(jwtUserInfo.getUserId());
    }
    return R.data(service.search(search));
  }

  @Operation(summary = "快速查询选项(有缓存)")
  @GetMapping("options")
  public R<List<OptionItem<PurchaseOrderItemVo>>> searchOptions(
    PurchaseOrderSearchParamPo search
  ) {
    JwtUserInfo jwtUserInfo = JwtUserInfo.fromHeader();
    if (jwtUserInfo != null) {
      search.setCurrentUserId(jwtUserInfo.getUserId());
    }
    return R.data(service.searchOptions(search));
  }

  @Operation(summary = "查询最后更新时间")
  @GetMapping("lastUpdateTime")
  public R<Date> searchLastUpdateTime(PurchaseOrderSearchParamPo search) {
    JwtUserInfo jwtUserInfo = JwtUserInfo.fromHeader();
    if (jwtUserInfo != null) {
      search.setCurrentUserId(jwtUserInfo.getUserId());
    }
    return R.data(service.searchLastUpdateTime(search));
  }

  @Operation(summary = "获取分页查询结果")
  @GetMapping("page")
  public R<Page<PurchaseOrderItemVo>> getPage(
    PurchaseOrderSearchParamPo search
  ) {
    JwtUserInfo jwtUserInfo = JwtUserInfo.fromHeader();
    if (jwtUserInfo != null) {
      search.setCurrentUserId(jwtUserInfo.getUserId());
    }
    return R.data(service.pageSearch(search));
  }

  @Operation(summary = "获取包括子表的查询结果")
  @GetMapping("page-with-child")
  public R<Page<?>> getPageWithChild(PurchaseOrderSearchParamPo search) {
    JwtUserInfo jwtUserInfo = JwtUserInfo.fromHeader();
    if (jwtUserInfo != null) {
      search.setCurrentUserId(jwtUserInfo.getUserId());
    }
    return R.data(service.pageWithChildSearch(search));
  }

  @Operation(summary = "仅获取子表的查询结果")
  @GetMapping("page-only-child/{parentId}")
  public R<Page<?>> getPageOnlyChild(
    @PathVariable Long parentId,
    PurchaseOrderSearchParamPo search
  ) {
    JwtUserInfo jwtUserInfo = JwtUserInfo.fromHeader();
    if (jwtUserInfo != null) {
      search.setCurrentUserId(jwtUserInfo.getUserId());
    }
    return R.data(service.pageOnlyChildSearch(parentId, search));
  }

  @Operation(summary = "查询是否后台下载")
  @GetMapping("getBackgroundExportFlag")
  public R<Boolean> getBackgroundExportFlag(PurchaseOrderSearchParamPo search) {
    JwtUserInfo jwtUserInfo = JwtUserInfo.fromHeader();
    if (jwtUserInfo != null) {
      search.setCurrentUserId(jwtUserInfo.getUserId());
    }
    return R.data(service.getBackgroundExportFlag(search));
  }

  @Operation(summary = "获取详情")
  @GetMapping("{id}")
  public R<PurchaseOrderVo> getVoById(@PathVariable Long id) {
    return R.data(() -> service.getVoById(id));
  }

  @Operation(summary = "获取采购单号相关的编号列表")
  @GetMapping("purchase-order-code/{texts}/ids")
  public R<List<Long>> getIdsByPurchaseOrderCode(@PathVariable String texts) {
    List<String> nameList = Arrays
      .stream(texts.split(","))
      .collect(Collectors.toList());
    return R.data(() -> service.getIdsByPurchaseOrderCode(nameList));
  }

  @Operation(summary = "获取编号相关的采购单号列表")
  @GetMapping("purchase-order-code/{ids}")
  public R<List<String>> getVoById(@PathVariable String ids) {
    List<Long> idList = Arrays
      .asList(ids.split(","))
      .stream()
      .map(Long::valueOf)
      .collect(Collectors.toList());
    return R.data(() -> service.getPurchaseOrderCodeByIds(idList));
  }

  @PreAuthorize("@am.canAccess('purchaseOrderCreate')")
  @Operation(summary = "新增")
  @PostMapping
  public R<Long> create(@Validated @RequestBody PurchaseOrderVo model) {
    return R.data(() -> service.create(model));
  }

  @PreAuthorize("@am.canAccess('purchaseOrderEdit')")
  @Operation(summary = "更新")
  @PutMapping
  public R update(@RequestBody PurchaseOrderVo model) {
    return R.run(() -> service.update(model));
  }

  @PreAuthorize("@am.canAccess('purchaseOrderEdit')")
  @Operation(summary = "编辑更新")
  @PutMapping("edit")
  public R updateForEdit(@RequestBody PurchaseOrderVo model) {
    return R.run(() -> service.updateForEdit(model));
  }

  @PreAuthorize("@am.canAccess('purchaseOrderDelete')")
  @Operation(summary = "删除")
  @DeleteMapping("{id}")
  public R delete(@PathVariable Long id) {
    return R.run(() -> service.delete(id));
  }

  @PreAuthorize("@am.canAccess('purchaseOrderDelete')")
  @Operation(summary = "批量删除")
  @DeleteMapping("batch")
  public R batchDelete(@RequestBody IdListPo po) {
    return R.run(() -> service.batchDelete(po.getIds()));
  }

  @PreAuthorize("@am.canAccess('purchaseOrderImport')")
  @Operation(summary = "导入预览")
  @PostMapping("import-preview")
  public R<List<ImportRow<PurchaseOrderImportPo>>> importPreview(
    @RequestBody SysFile sysFile,
    @RequestParam(name = "template", required = false) Long templateId,
    @RequestParam(
      name = "allowOverrides",
      defaultValue = "false"
    ) boolean allowOverrides
  ) {
    return R.data(() ->
      service.importPreview(sysFile, templateId, allowOverrides)
    );
  }

  @PreAuthorize("@am.canAccess('purchaseOrderImport')")
  @Operation(summary = "完成导入")
  @PostMapping("import-done")
  public R importDone(
    @RequestBody List<ImportRow<PurchaseOrderImportPo>> rows,
    @RequestParam(name = "template", required = false) Long templateId
  ) {
    return R.run(() -> service.importDone(rows, templateId));
  }

  @Operation(summary = "下载导入模版")
  @GetMapping("import/template")
  public void downloadImportTemplate(HttpServletResponse response)
    throws IOException {
    ResponseUtils.setAttachmentFileName(response, "采购订单导入模版.xlsx");
    InputStream inputStream = new ClassPathResource(
      "templates/PurchaseOrder.xlsx"
    )
      .getInputStream();
    StreamUtils.copy(inputStream, response.getOutputStream());
  }

  @Operation(summary = "导出")
  @GetMapping("export")
  @PreAuthorize("@am.canAccess('purchaseOrderExport')")
  public void export(
    @RequestParam(name = "template", required = false) Long templateId,
    PurchaseOrderSearchParamPo search,
    HttpServletResponse response
  ) throws Exception {
    JwtUserInfo jwtUserInfo = JwtUserInfo.fromHeader();
    if (jwtUserInfo != null) {
      search.setCurrentUserId(jwtUserInfo.getUserId());
    }
    service.export(templateId, search, response);
  }

  @PreAuthorize("@am.canAccess('purchaseOrderWithdraw')")
  @Operation(summary = "请款")
  @PostMapping("withdraw")
  public R withdraw(@RequestBody IdListPo po) {
    return R.run(() -> service.withdraw(po.getIds()));
  }

  @PreAuthorize("@am.canAccess('purchaseOrderPlaceAnOrder')")
  @Operation(summary = "下单")
  @PostMapping("placeAnOrder")
  public R placeAnOrder(@RequestBody IdPo po) {
    return R.run(() -> service.placeAnOrder(po.getId()));
  }

  @PreAuthorize("@am.canAccess('purchaseOrderEndDeliverys')")
  @Operation(summary = "结束到货")
  @PostMapping("endDeliverys")
  public R endDeliverys(@RequestBody IdPo po) {
    return R.run(() -> service.endDeliverys(po.getId()));
  }

  @PreAuthorize("@am.canAccess('purchaseOrderCashOut')")
  @Operation(summary = "请款")
  @PostMapping("cashOut")
  public R cashOut(@RequestBody IdPo po) {
    return R.run(() -> service.cashOut(po.getId()));
  }

  @PreAuthorize("@am.canAccess('purchaseOrderMessagereminder')")
  @Operation(summary = "钉钉消息提醒")
  @PostMapping("messagereminder")
  public R messagereminder() {
    return R.run(() -> service.messagereminder());
  }

  @Operation(summary = "根据日期同步表单确定操作")
  @PostMapping("sync-date-order/confirm")
  public R<?> syncDateOrderConfirm(@RequestBody JSONObject data) {
    return R.run(() -> service.syncDateOrderConfirm(data));
  }

  @Operation(summary = "根据订单号同步表单确定操作")
  @PostMapping("sync-order-sn/confirm")
  public R<?> syncOrderSnConfirm(@RequestBody JSONObject data) {
    return R.run(() -> service.syncOrderSnConfirm(data));
  }

  @PreAuthorize("@am.canAccess('purchaseOrderPullPurchaseOrder')")
  @Operation(summary = "同步领星采购订单")
  @PostMapping("pullPurchaseOrder")
  public R pullPurchaseOrder() {
    return R.run(() -> service.pullPurchaseOrder());
  }

  @PreAuthorize("@am.canAccess('purchaseOrderCancellation')")
  @Operation(summary = "作废")
  @PostMapping("cancellation")
  public R cancellation(@RequestBody IdListPo po) {
    return R.run(() -> service.cancellation(po.getIds()));
  }

  @PreAuthorize("@am.canAccess('purchaseOrderPlaceOrder')")
  @Operation(summary = "下单")
  @PostMapping("placeOrder")
  public R placeOrder(@RequestBody IdListPo po) {
    return R.run(() -> service.placeOrder(po.getIds()));
  }

  @PreAuthorize("@am.canAccess('purchaseOrderEndDelivery')")
  @Operation(summary = "结束到货")
  @PostMapping("endDelivery")
  public R endDelivery(@RequestBody IdListPo po) {
    return R.run(() -> service.endDelivery(po.getIds()));
  }

  @PreAuthorize("@am.canAccess('purchaseOrderPurchasesOrderReview')")
  @Operation(summary = "审核")
  @PostMapping("purchasesOrderReview")
  public R purchasesOrderReview(@RequestBody IdPo po) {
    return R.run(() -> service.purchasesOrderReview(po.getId()));
  }

  @PreAuthorize("@am.canAccess('purchaseOrderPushInStorage')")
  @Operation(summary = "下推采购入库单")
  @PostMapping("pushInStorage")
  public R pushInStorage(@RequestBody IdPo po) {
    return R.run(() -> service.pushInStorage(po.getId()));
  }

  /**
   * 视图选项卡标题上显示计数
   */
  @Operation(summary = "视图选项卡标题上显示计数")
  @GetMapping("getTabHeaderShowTotal")
  public R<Map> getTabHeaderShowTotal() {
    return R.data(() -> service.getTabHeaderShowTotal());
  }

  @Operation(summary = "全部")
  @GetMapping("complete")
  public R<List<PurchaseOrderItemVo>> complete(
    PurchaseOrderSearchParamPo search
  ) {
    JwtUserInfo jwtUserInfo = JwtUserInfo.fromHeader();
    if (jwtUserInfo != null) {
      search.setCurrentUserId(jwtUserInfo.getUserId());
    }
    return R.data(() -> service.complete(search));
  }

  @Operation(summary = "全部分页")
  @GetMapping("completePage")
  public R<Page<PurchaseOrderItemVo>> completePage(
    PurchaseOrderSearchParamPo search
  ) {
    JwtUserInfo jwtUserInfo = JwtUserInfo.fromHeader();
    if (jwtUserInfo != null) {
      search.setCurrentUserId(jwtUserInfo.getUserId());
    }
    return R.data(() -> service.completePage(search));
  }

  @Operation(summary = "全部包括子表的查询结果")
  @GetMapping("completePage-with-child")
  public R<Page<?>> completePageWithChild(PurchaseOrderSearchParamPo search) {
    JwtUserInfo jwtUserInfo = JwtUserInfo.fromHeader();
    if (jwtUserInfo != null) {
      search.setCurrentUserId(jwtUserInfo.getUserId());
    }
    return R.data(service.completePageWithChildSearch(search));
  }

  @Operation(summary = "全部最后更新时间")
  @GetMapping("completeLastUpdateTime")
  public R<Date> completeLastUpdateTime(PurchaseOrderSearchParamPo search) {
    JwtUserInfo jwtUserInfo = JwtUserInfo.fromHeader();
    if (jwtUserInfo != null) {
      search.setCurrentUserId(jwtUserInfo.getUserId());
    }
    return R.data(() -> service.completeLastUpdateTime(search));
  }

  @Operation(summary = "待提交")
  @GetMapping("changes-to-be-committed")
  public R<List<PurchaseOrderItemVo>> changesToBeCommitted(
    PurchaseOrderSearchParamPo search
  ) {
    JwtUserInfo jwtUserInfo = JwtUserInfo.fromHeader();
    if (jwtUserInfo != null) {
      search.setCurrentUserId(jwtUserInfo.getUserId());
    }
    return R.data(() -> service.changesToBeCommitted(search));
  }

  @Operation(summary = "待提交分页")
  @GetMapping("changes-to-be-committedPage")
  public R<Page<PurchaseOrderItemVo>> changesToBeCommittedPage(
    PurchaseOrderSearchParamPo search
  ) {
    JwtUserInfo jwtUserInfo = JwtUserInfo.fromHeader();
    if (jwtUserInfo != null) {
      search.setCurrentUserId(jwtUserInfo.getUserId());
    }
    return R.data(() -> service.changesToBeCommittedPage(search));
  }

  @Operation(summary = "待提交包括子表的查询结果")
  @GetMapping("changes-to-be-committedPage-with-child")
  public R<Page<?>> changesToBeCommittedPageWithChild(
    PurchaseOrderSearchParamPo search
  ) {
    JwtUserInfo jwtUserInfo = JwtUserInfo.fromHeader();
    if (jwtUserInfo != null) {
      search.setCurrentUserId(jwtUserInfo.getUserId());
    }
    return R.data(service.changesToBeCommittedPageWithChildSearch(search));
  }

  @Operation(summary = "待提交最后更新时间")
  @GetMapping("changes-to-be-committedLastUpdateTime")
  public R<Date> changesToBeCommittedLastUpdateTime(
    PurchaseOrderSearchParamPo search
  ) {
    JwtUserInfo jwtUserInfo = JwtUserInfo.fromHeader();
    if (jwtUserInfo != null) {
      search.setCurrentUserId(jwtUserInfo.getUserId());
    }
    return R.data(() -> service.changesToBeCommittedLastUpdateTime(search));
  }

  @Operation(summary = "待审批")
  @GetMapping("the-approval-is-pending")
  public R<List<PurchaseOrderItemVo>> theApprovalIsPending(
    PurchaseOrderSearchParamPo search
  ) {
    JwtUserInfo jwtUserInfo = JwtUserInfo.fromHeader();
    if (jwtUserInfo != null) {
      search.setCurrentUserId(jwtUserInfo.getUserId());
    }
    return R.data(() -> service.theApprovalIsPending(search));
  }

  @Operation(summary = "待审批分页")
  @GetMapping("the-approval-is-pendingPage")
  public R<Page<PurchaseOrderItemVo>> theApprovalIsPendingPage(
    PurchaseOrderSearchParamPo search
  ) {
    JwtUserInfo jwtUserInfo = JwtUserInfo.fromHeader();
    if (jwtUserInfo != null) {
      search.setCurrentUserId(jwtUserInfo.getUserId());
    }
    return R.data(() -> service.theApprovalIsPendingPage(search));
  }

  @Operation(summary = "待审批包括子表的查询结果")
  @GetMapping("the-approval-is-pendingPage-with-child")
  public R<Page<?>> theApprovalIsPendingPageWithChild(
    PurchaseOrderSearchParamPo search
  ) {
    JwtUserInfo jwtUserInfo = JwtUserInfo.fromHeader();
    if (jwtUserInfo != null) {
      search.setCurrentUserId(jwtUserInfo.getUserId());
    }
    return R.data(service.theApprovalIsPendingPageWithChildSearch(search));
  }

  @Operation(summary = "待审批最后更新时间")
  @GetMapping("the-approval-is-pendingLastUpdateTime")
  public R<Date> theApprovalIsPendingLastUpdateTime(
    PurchaseOrderSearchParamPo search
  ) {
    JwtUserInfo jwtUserInfo = JwtUserInfo.fromHeader();
    if (jwtUserInfo != null) {
      search.setCurrentUserId(jwtUserInfo.getUserId());
    }
    return R.data(() -> service.theApprovalIsPendingLastUpdateTime(search));
  }

  @Operation(summary = "待下单")
  @GetMapping("staging-release-order-parts")
  public R<List<PurchaseOrderItemVo>> stagingReleaseOrderParts(
    PurchaseOrderSearchParamPo search
  ) {
    JwtUserInfo jwtUserInfo = JwtUserInfo.fromHeader();
    if (jwtUserInfo != null) {
      search.setCurrentUserId(jwtUserInfo.getUserId());
    }
    return R.data(() -> service.stagingReleaseOrderParts(search));
  }

  @Operation(summary = "待下单分页")
  @GetMapping("staging-release-order-partsPage")
  public R<Page<PurchaseOrderItemVo>> stagingReleaseOrderPartsPage(
    PurchaseOrderSearchParamPo search
  ) {
    JwtUserInfo jwtUserInfo = JwtUserInfo.fromHeader();
    if (jwtUserInfo != null) {
      search.setCurrentUserId(jwtUserInfo.getUserId());
    }
    return R.data(() -> service.stagingReleaseOrderPartsPage(search));
  }

  @Operation(summary = "待下单包括子表的查询结果")
  @GetMapping("staging-release-order-partsPage-with-child")
  public R<Page<?>> stagingReleaseOrderPartsPageWithChild(
    PurchaseOrderSearchParamPo search
  ) {
    JwtUserInfo jwtUserInfo = JwtUserInfo.fromHeader();
    if (jwtUserInfo != null) {
      search.setCurrentUserId(jwtUserInfo.getUserId());
    }
    return R.data(service.stagingReleaseOrderPartsPageWithChildSearch(search));
  }

  @Operation(summary = "待下单最后更新时间")
  @GetMapping("staging-release-order-partsLastUpdateTime")
  public R<Date> stagingReleaseOrderPartsLastUpdateTime(
    PurchaseOrderSearchParamPo search
  ) {
    JwtUserInfo jwtUserInfo = JwtUserInfo.fromHeader();
    if (jwtUserInfo != null) {
      search.setCurrentUserId(jwtUserInfo.getUserId());
    }
    return R.data(() -> service.stagingReleaseOrderPartsLastUpdateTime(search));
  }

  @Operation(summary = "待到货")
  @GetMapping("awaiting-arrival")
  public R<List<PurchaseOrderItemVo>> awaitingArrival(
    PurchaseOrderSearchParamPo search
  ) {
    JwtUserInfo jwtUserInfo = JwtUserInfo.fromHeader();
    if (jwtUserInfo != null) {
      search.setCurrentUserId(jwtUserInfo.getUserId());
    }
    return R.data(() -> service.awaitingArrival(search));
  }

  @Operation(summary = "待到货分页")
  @GetMapping("awaiting-arrivalPage")
  public R<Page<PurchaseOrderItemVo>> awaitingArrivalPage(
    PurchaseOrderSearchParamPo search
  ) {
    JwtUserInfo jwtUserInfo = JwtUserInfo.fromHeader();
    if (jwtUserInfo != null) {
      search.setCurrentUserId(jwtUserInfo.getUserId());
    }
    return R.data(() -> service.awaitingArrivalPage(search));
  }

  @Operation(summary = "待到货包括子表的查询结果")
  @GetMapping("awaiting-arrivalPage-with-child")
  public R<Page<?>> awaitingArrivalPageWithChild(
    PurchaseOrderSearchParamPo search
  ) {
    JwtUserInfo jwtUserInfo = JwtUserInfo.fromHeader();
    if (jwtUserInfo != null) {
      search.setCurrentUserId(jwtUserInfo.getUserId());
    }
    return R.data(service.awaitingArrivalPageWithChildSearch(search));
  }

  @Operation(summary = "待到货最后更新时间")
  @GetMapping("awaiting-arrivalLastUpdateTime")
  public R<Date> awaitingArrivalLastUpdateTime(
    PurchaseOrderSearchParamPo search
  ) {
    JwtUserInfo jwtUserInfo = JwtUserInfo.fromHeader();
    if (jwtUserInfo != null) {
      search.setCurrentUserId(jwtUserInfo.getUserId());
    }
    return R.data(() -> service.awaitingArrivalLastUpdateTime(search));
  }

  @Operation(summary = "已完成")
  @GetMapping("completed")
  public R<List<PurchaseOrderItemVo>> completed(
    PurchaseOrderSearchParamPo search
  ) {
    JwtUserInfo jwtUserInfo = JwtUserInfo.fromHeader();
    if (jwtUserInfo != null) {
      search.setCurrentUserId(jwtUserInfo.getUserId());
    }
    return R.data(() -> service.completed(search));
  }

  @Operation(summary = "已完成分页")
  @GetMapping("completedPage")
  public R<Page<PurchaseOrderItemVo>> completedPage(
    PurchaseOrderSearchParamPo search
  ) {
    JwtUserInfo jwtUserInfo = JwtUserInfo.fromHeader();
    if (jwtUserInfo != null) {
      search.setCurrentUserId(jwtUserInfo.getUserId());
    }
    return R.data(() -> service.completedPage(search));
  }

  @Operation(summary = "已完成包括子表的查询结果")
  @GetMapping("completedPage-with-child")
  public R<Page<?>> completedPageWithChild(PurchaseOrderSearchParamPo search) {
    JwtUserInfo jwtUserInfo = JwtUserInfo.fromHeader();
    if (jwtUserInfo != null) {
      search.setCurrentUserId(jwtUserInfo.getUserId());
    }
    return R.data(service.completedPageWithChildSearch(search));
  }

  @Operation(summary = "已完成最后更新时间")
  @GetMapping("completedLastUpdateTime")
  public R<Date> completedLastUpdateTime(PurchaseOrderSearchParamPo search) {
    JwtUserInfo jwtUserInfo = JwtUserInfo.fromHeader();
    if (jwtUserInfo != null) {
      search.setCurrentUserId(jwtUserInfo.getUserId());
    }
    return R.data(() -> service.completedLastUpdateTime(search));
  }

  @Operation(summary = "已作废")
  @GetMapping("have-been-voided")
  public R<List<PurchaseOrderItemVo>> haveBeenVoided(
    PurchaseOrderSearchParamPo search
  ) {
    JwtUserInfo jwtUserInfo = JwtUserInfo.fromHeader();
    if (jwtUserInfo != null) {
      search.setCurrentUserId(jwtUserInfo.getUserId());
    }
    return R.data(() -> service.haveBeenVoided(search));
  }

  @Operation(summary = "已作废分页")
  @GetMapping("have-been-voidedPage")
  public R<Page<PurchaseOrderItemVo>> haveBeenVoidedPage(
    PurchaseOrderSearchParamPo search
  ) {
    JwtUserInfo jwtUserInfo = JwtUserInfo.fromHeader();
    if (jwtUserInfo != null) {
      search.setCurrentUserId(jwtUserInfo.getUserId());
    }
    return R.data(() -> service.haveBeenVoidedPage(search));
  }

  @Operation(summary = "已作废包括子表的查询结果")
  @GetMapping("have-been-voidedPage-with-child")
  public R<Page<?>> haveBeenVoidedPageWithChild(
    PurchaseOrderSearchParamPo search
  ) {
    JwtUserInfo jwtUserInfo = JwtUserInfo.fromHeader();
    if (jwtUserInfo != null) {
      search.setCurrentUserId(jwtUserInfo.getUserId());
    }
    return R.data(service.haveBeenVoidedPageWithChildSearch(search));
  }

  @Operation(summary = "已作废最后更新时间")
  @GetMapping("have-been-voidedLastUpdateTime")
  public R<Date> haveBeenVoidedLastUpdateTime(
    PurchaseOrderSearchParamPo search
  ) {
    JwtUserInfo jwtUserInfo = JwtUserInfo.fromHeader();
    if (jwtUserInfo != null) {
      search.setCurrentUserId(jwtUserInfo.getUserId());
    }
    return R.data(() -> service.haveBeenVoidedLastUpdateTime(search));
  }
}
